<template>
  <div>
    <FormPanel
      ref="baseInfo"
      :list="initFormBase"
      :cols="1"
      :labelWidth="180"
      formType="edit"
      :isSubmitBtn="false"
    />
    <div style="text-align:center">
      <el-button size="small" type="primary" icon="el-icon-edit" @click="saveDialog">提 交</el-button>
      <el-button size="small" type="primary" icon="el-icon-edit" @click="reset">重 置</el-button>
    </div>
  </div>
</template>
<script>
import {dictionary} from '@/utils/dictMixin';
import {applyBoClose,} from '@/api/partsmanage/purchaseManage/purchaseSubmit';

export default {
  name: "closeBOForm",
  // components: {},
  props: {
    value: { default: null }
  },
  mixins: [dictionary],
  data() {
    return {
      formData: {partOrderDetailIds:''},
      initFormBase: this.initFormBaseFun()
    };
  },
  mounted() {
    console.log(this.value)
    // this.formData.id = this.value.partOrder.id
    let data = []
    this.value.forEach(row =>{
      data.push(row.id);
    })
    this.formData.partOrderDetailIds = data.join(",");
  },
  methods: {
    reset(){
      this.initFormBase.forEach(x=>{
        x.initialValue = null;
      })
    },
    //基本表单信息
    initFormBaseFun() {
      return [
        {
          type: 'TEXT_AREA',
          label: '申请关闭原因',
          fieldName: 'boReason',
          rules: [
            {required: false, trigger: 'change', message: '请输入关闭原因'},
          ],
          maxlength:80
        },
        { type: 'TEXT_AREA', label: '备注', fieldName: 'remark' ,maxlength:80},
      ];
    },
    //保存
    async saveDialog() {
      const [err, data] = await this.$refs.baseInfo.GET_FORM_DATA();
      this.$confirm('确定取消?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(()=>{
        this.formData = Object.assign({}, this.formData, data);
        console.log(this.formData)
        applyBoClose(this.formData).then(res =>{
          if (res.resultCode === 200) {
            this.$notify.warning({title: '提示信息', message:res.data.msg});
          }
          // 重新加载
          this.closeDialog('refresh');
        })
      })
      
    },
    //取消操作
    closeDialog(type) {
      this.$emit('close', type);
    }
  }
};
</script>

<style lang="less" scoped>
</style>
